﻿@model IList<DataAccess.HomeGaleria>
@{
    ViewBag.Title = "Galeria Home";
}
<div class="centralcontainer rounded-corners">
    <!-- BODY -->
    <table width="100%" cellpadding="20px">
        <tr>
            <td colspan="2">
                <!-- MENSAJERIA -->
                <div id="DivMensajeria" style="display: none;">
                    @Html.Partial("Fail", "")
                    @Html.Partial("Warning", "")
                    @Html.Partial("Success", "")
                </div>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <h1 class="rounded-corners">
                    Rotativo
                </h1>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <h2 class="rounded-corners">
                    Insertar nueva imagen
                </h2>
            </td>
        </tr>
        <form action="@Url.Action("InsertImage")" enctype="multipart/form-data" method="post">
        <tr>
            <td>
                Imagen
            </td>
            <td>
                <input type="file" required="required" name="imagen" />
            </td>
        </tr>
        <tr>
            <td>
                Orden
            </td>
            <td>
                <input type="number" required="required" min="1" max="100" name="orden" />
            </td>
        </tr>
        <tr>
            <td>
            </td>
            <td>
                <input type="submit" value="Guardar" class="boton" style="border-width: 0px; margin-left: 5px;" />
            </td>
        </tr>
        </form>
        <tr>
            <td>
            </td>
        </tr>
    </table>
    <hr class='hrGray'>
        @if (Model.Count > 0)
        {
            <table class="uploaded">
                @foreach (var rot in Model)
                {
                    <tr>
                        <td>
                            <img src="@Url.Action("GetImagen", "Imagen", new { idImagen = rot.IdImagen })" alt="ARRB" />
                        </td>
                        <td>
                            <form action="@Url.Action("UpdateOrden")" enctype="application/x-www-form-urlencoded" method="post" class="cambiarOrden">
                            Orden:
                            <input type="hidden" value="@rot.Id" name="idImagenGaleria" />
                            <input type="number" required="required" min="1" max="100" name="orden" size="10" value="@rot.Orden"/>
                            <br />
                            <br />
                            <br />
                            <input type="submit" value="Guardar" class="boton" style="border-width: 0px; float: left;" />
                            </form>
                            <form action="@Url.Action("DeleteImagen")" enctype="application/x-www-form-urlencoded" method="post">
                                <input type="hidden" value="@rot.Id" name="idImagenGaleria" />
                                <img src="@Url.Content("~/Content/img/Botones/xeliminar.png")" alt="arrb" class="deleteImagen" style="cursor:pointer; float: left; margin-left: 40px;"/>
                            </form>
                        </td>
                    </tr>
                }
            </table>
        }
        else
        {
            @Html.Partial("Warning", "No se han asociado imagenes a la galeria.")
        }
</div>
<!-- CONFIRMATION -->
<div id="dialog-confirm" style="display: none;" title="¿Eliminar permanentemente?">
    <p>
        ¿Esta seguro que desea eliminar esta imagen del sistema? 
    </p>
    <p>
        Esta acción no se puede revertir.
    </p>
</div>
@section header{
    <script type="text/javascript" language="javascript">
        $(function () {
            $('.message').hide();
            $('#DivMensajeria').show();
            $('.divformulario').find('.warning').show();

            $('.deleteImagen').click(function () {
                var form = $(this).parent();
                $("#dialog-confirm").dialog({
                    resizable: false,
                    modal: true,
                    buttons: {
                        'Eliminar': function () {
                            $("#Loader").show();
                            $.post(form.attr('action'), form.serialize(), function (response) {
                                if (response.success == true) {
                                    form.closest('tr').fadeOut();
                                    ShowSuccess(response.mensaje);
                                }
                                else {
                                    ShowFail(response.mensaje);
                                }
                                $("#Loader").hide();
                            });
                            $(this).dialog('close');
                        },
                        'Cancelar': function () {
                            $(this).dialog('close');
                        }
                    }
                });
                return false;
            });

            $('.cambiarOrden').submit(function () {
                $.post($(this).attr('action'), $(this).serialize(), function (response) {
                    if (response.success == true) {
                        ShowSuccess(response.mensaje);
                    }
                    else {
                        ShowFail(response.mensaje);
                    }
                    $("#Loader").hide();
                });
                return false;
            });

        });
    </script>
}
@section navegacion{
    <a href="@Url.Action("Index", "Home")">Home </a>&nbsp;&gt;&nbsp;
    <label>
        Galeria Home
    </label>
}
